
$(function(){
	var base = $('base').attr('href');
	var resourceId = getUrlParam('resourceId');
	if(!isEmpty(resourceId)){
		new Vue({
			el: '#resourceBean',
			data: {
				success:false,
				result:{},
				path:''
			},
			created: function(){
				console.log('created: ');
				var _this = this;
				get('resource/getResource', function(data){
					if(data.success){
						var res = data.result;
						var path = '';
						if(res.pathType==0){
							path = base+'resource/download/'+res.resourceId;
						}else{
							path = res.resourcePath;
						}
						_this.success = data.success;
						_this.result = res;
						_this.path = path;
					}else {
						spop(data.result, 'error');
					}
				}, {
					resourceId: resourceId
				});
			},
			mounted: function(){
				console.log('mounted: ');
				//复制下载地址
				new ClipboardJS('#copyBtn');
			},
			updated: function(){
				console.log('updated: ');
				var _this = this;
				//二维码
				$('#code').qrcode({
			        render: 'canvas', //table 模式兼容 IE低版本
			        width: 150,
			        height: 150,
			        typeNumber: -1,//计算模式
					correctLevel: QRErrorCorrectLevel.H,//纠错等级    
					background: "#ffffff",//背景颜色    
					foreground: "#000000", //前景颜色 
					text: _this.path
			    });
			},
			methods: {
				uriType: function(pathType){
					//0自己的资源，1其它网站地址如百度网盘分享地址，2电驴，3磁力，4迅雷
					if(pathType==0){
						return '下载';
					}else if(pathType==1){
						return '打开';
					}else if(pathType==2){
						return '电驴下载';
					}else if(pathType==3){
						return '磁力下载';
					}else if(pathType==4){
						return '迅雷下载';
					}
				},
				//点击下载
				download: function(type,id,path){
					if(type==0){
						window.open(base+'resource/download/'+id);
					}else{
						window.open(path);
						get('resource/downCount/'+id, function(data){
		        			if(!data.success){
		        				spop(data.result, 'error');
		        			}
		        		});
					}
				}
			}
		});
	}
	
});